<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Join_model extends CI_Model {

	function __construct() {
		parent::__construct();

		$this->load->library('LogSql');
	}

	/**
	 * 이미 가입된 회원인지 체크
	 */
	function is_already_user($ipin_di) {
		log_message('debug',"#### Join_model::is_already_user($ipin_di)");

		$this->db->where('ipin_di', $ipin_di);
		$this->db->where('use_yn', 'Y');
		$this->db->from('tb_member');
		$result = $this->db->count_all_results();

		$this->logsql->log_sql();
		$this->logsql->log_result($result);

		if ($result > 0) {
			return TRUE;
		}
        return FALSE;
	}
	
	/**
	 * 아이디 중복 체크
	 */
	function is_already_id($user_id) {
		log_message('debug',"#### Join_model::is_already_id($user_id)");

		$this->db->where('user_id', $user_id);
		$this->db->from('tb_member');
		$result = $this->db->count_all_results();

		$this->logsql->log_sql();
		$this->logsql->log_result($result);

		if ($result > 0) {
			return TRUE;
		}
        return FALSE;
	}

	/**
	 * 닉네임 중복 체크
	 */	
	function is_already_nickname($nickname) {
		log_message('debug',"#### Join_model::is_already_nickname($nickname)");

		$this->db->where('nickname', $nickname);
		$this->db->where('use_yn', 'Y');
		$this->db->from('tb_member');
		$result = $this->db->count_all_results();
		
		$this->logsql->log_sql();
		$this->logsql->log_result($result);

		if ($result > 0) {
			return TRUE;
		}
        return FALSE;
	}
	
	/**
	 * 이메일 중복 체크
	 */	
	function is_already_email($email) {
		log_message('debug',"#### Join_model::is_already_email($email)");

		$this->db->where('email', $email);
		$this->db->where('use_yn', 'Y');
		$this->db->from('tb_member');
		$result = $this->db->count_all_results();
		
		$this->logsql->log_sql();
		$this->logsql->log_result($result);

		if ($result > 0) {
			return TRUE;
		}
        return FALSE;
	}
	
	/**
	 * 회원 등록
	 */
	function insert_member($member) {
		log_message('debug', "#### Join_model::insert_member($member)");
			
		$this->db->trans_start();
		
		// 회원정보 입력
		$this->db->set($member);
		$this->db->set('login_dt',  'now()', FALSE);
		$this->db->set('create_dt', 'now()', FALSE);
		$this->db->set('update_dt', 'now()', FALSE);
		$this->db->insert('tb_member') or $this->logsql->log_sql('error');

		$this->logsql->log_sql();

		// 포인트 기본값 입력
		$this->db->set('user_id'    , $member['user_id']);
		$this->db->set('point'      , '0');
		$this->db->set('create_dt'  , 'now()', FALSE);
		$this->db->set('update_dt'  , 'now()', FALSE);
		$this->db->insert('tb_point') or $this->logsql->log_sql('error');

		$this->logsql->log_sql();

		$this->db->trans_complete();

		if ($this->db->trans_status() === FALSE) {
			log_message('error', '==== 회원 등록 DB업데이트중 에러 발생 ========================');
			die('에러 발생');
		}
		return TRUE;
	}
}

/* End of file join_model.php */
/* Location: ./application/models/member/join_model.php */